<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="/web/header.jsp"%>
<title>Insert title here</title>
</head>
<body>
<fieldset class="layui-elem-field" style="margin:10px">
	<legend>员工添加</legend>
  	<div class="layui-field-box">
    	<form   class="layui-form layui-form-pane">
    	 <div class="layui-form-item">
    		<label class="layui-form-label">员工</label>
    		<div class="layui-input-inline">
     		 	<select name='codeEmp' required lay-verify="required"></select>
    		</div>
  		</div>
  		<div class="layui-form-item">
    		<label class="layui-form-label">项目</label>
    		<div class="layui-input-inline">
				<select name='codePro' required lay-verify="required"></select>    		
			</div>
  		</div>
  		<div class="layui-form-item">
    		<label class="layui-form-label">绩效</label>
    		<div class="layui-input-inline">
				<input type="text" name="score" required  lay-verify="required" placeholder="请输入绩效" autocomplete="off" class="layui-input">    		
			</div>
  		</div>
  		<div class="layui-form-item">
    		<div class="layui-input-block">
    			<input type="button" value="确定" class="layui-btn" lay-submit lay-filter="add">
    			<input type="reset" value="重置" class="layui-btn layui-btn-primary">
    			<input type="button" value="关闭" class="layui-btn" onclick="layerClose()">
    		</div>
  		</div>
  		<input type="hidden" name="action" value="add">
    	</form>
  	</div>
</fieldset>
<script type="text/javascript">

function initEmp(){//从数据库中初始化下拉框中的数据
	ajax('/EmployeeServlet',{action:'list'},'json',function(data){
		var opt="<option value=''>请选择员工</option>"
		$.each(data,function(){
			opt+="<option value='"+this.code+"'>"+this.name+"</option>"
		})
		$("select[name='codeEmp']").html(opt);
		form.render();
		
	})
}

function initPro(){//从数据库中初始化下拉框中的数据
	ajax('/ProjectServlet',{action:'list'},'json',function(data){
		var opt="<option value=''>请选择项目</option>"
		$.each(data,function(){
			opt+="<option value='"+this.code+"'>"+this.name+"</option>"
		})
		$("select[name='codePro']").html(opt);
		form.render();
		
	})
}
initPro();
initEmp();

formSubmit('add','/ScoreServlet','text',function(data){
	if(data==1){
		layer.msg("添加成功",layerClose) 
	}else if(data=="repeat"){
		layer.msg("编号重复")
	}else{	
		layer.msg("添加失败") 
	}
})
</script>
</body>
</html>